<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Repository\Smilapp\SmilappYiJianRepository;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use App\Repository\AppUser\TouTiaoRepository;
use App\Repository\AppUser\TouTiaoUserOrderRepository;
use App\Repository\UploadRepository;
use Illuminate\Support\Facades\Cache;
use Carbon\Carbon;

/**
 * @OA\Tag(
 *     name="后台菜单模块",
 *     description="菜单模块",
 * )
 */
class YiJianController extends BaseController
{
  public function __construct(SmilappYiJianRepository $SmilappYiJianRepository)
  {
    $this->orderKeysTime = 10;
    $this->model = $SmilappYiJianRepository;
  }
  public function submitYijian(Request $request)
  {
    $params = $request->all();
    // var_dump($params);
    // 先判断用户是否存在
    $resUser = DB::Table('toutiao_user')->where(['shop_id' => $params['shopId'], 'id' => $params['code']])->first();
    if (!$resUser) {
      return $this->returnMsg(100, '请您登录后再提建议');
    }
    // var_dump($params);
    if (empty($resUser->updated_at)) {
      return $this->returnMsg(101, '请您退出刷新后重新进入');
    }
    if (!empty($resUser->updated_at) &&  strtotime($resUser->updated_at) > (time() - 600)) {
      return $this->returnMsg(101, '请您退出刷新后重新进入');
    }

    // var_dump($res);
    $imgs = '';
    if (!empty($params['img'])) {
      $imgs = implode(',', $params['img']);
    }
    $data = [
      'shop_id' => $params['shopId'],
      'user_id' => $params['code'],
      'pic' => $imgs,
      'phone' => !empty($params['phone']) ? $params['phone'] : '',
      'type' => !empty($params['type']) ? $params['type'] : '',
      'introduction' => $params['introduction'],
    ];
    return $this->model->add($data);
    return $this->returnMsg(200, '请保持电话畅通,客服会与您联系', $res);
  }
}
